package com.industry.examinaion.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.industry.examinaion.dal.dataobject.ExaminaionPaper;
import com.industry.examinaion.dal.dataobject.ExaminaionPaperQuestion;
import com.industry.examinaion.dal.db.ExaminaionPaperMapper;
import com.industry.examinaion.dal.db.ExaminaionPaperQuestionMapper;
import com.industry.examinaion.dal.dto.SubmitPaperDto;
import com.industry.framework.core.generic.AbstractCoreGenericController;
import com.industry.framework.core.generic.AbstractCoreGenericService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

@Service
public class ExaminaionPaperService extends AbstractCoreGenericService<ExaminaionPaper,String> {


    @Resource
    ExaminaionPaperQuestionMapper examinaionPaperQuestionMapper;

    @Resource
    ExaminaionPaperMapper examinaionPaperMapper;

    public void submit(SubmitPaperDto submitPaperDto){
        String paperId = submitPaperDto.getExaminaionPaperId();
        //试卷数据
        ExaminaionPaper examinaionPaper = examinaionPaperMapper.selectById(paperId);
        if(examinaionPaper == null){
            return;
        }
        //试题数据
        List<ExaminaionPaperQuestion> examinaionPaperQuestions = examinaionPaperQuestionMapper
                .selectList(Wrappers.lambdaQuery(ExaminaionPaperQuestion.class)
                .eq(ExaminaionPaperQuestion::getExaminaionPaperId,paperId));

        List<SubmitPaperDto.AnswerResult> answers = submitPaperDto.getAnswers();
        Map<String, List<SubmitPaperDto.AnswerResult>> collect = answers.stream()
                .collect(Collectors.groupingBy(SubmitPaperDto.AnswerResult::getExaminaionQuestionId));


    }

//    public void createExaminaionPaper''









}
